package com.jindy.module.statement.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.jindy.common.core.domain.entity.SysUser;
import com.jindy.common.utils.SecurityUtils;
import com.jindy.system.service.ISysUserService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.jindy.common.annotation.Log;
import com.jindy.common.core.controller.BaseController;
import com.jindy.common.core.domain.AjaxResult;
import com.jindy.common.enums.BusinessType;
import com.jindy.module.statement.domain.Statement;
import com.jindy.module.statement.service.IStatementService;
import com.jindy.common.utils.poi.ExcelUtil;
import com.jindy.common.core.page.TableDataInfo;

/**
 * 结算单Controller
 *
 * @author ruoyi
 * @date 2022-10-27
 */
@RestController
@RequestMapping("/module/statement")
public class StatementController extends BaseController
{
    @Autowired
    private IStatementService statementService;
    @Autowired
    private ISysUserService sysUserService;

    /**
     * 查询结算单列表
     */
    @PreAuthorize("@ss.hasPermi('module:statement:list')")
    @GetMapping("/list")
    public TableDataInfo list(Statement statement)
    {
//        //添加权限
//        SysUser sysUser = SecurityUtils.getLoginUser().getUser();
//        statement.setUserId(sysUser.getUserId());

        startPage();
        List<Statement> list = statementService.selectStatementList(statement);
        return getDataTable(list);
    }

    /**
     * 导出结算单列表
     */
    @Log(title = "结算单", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('module:statement:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, Statement statement)
    {
//        //添加权限
//        SysUser sysUser = SecurityUtils.getLoginUser().getUser();
//        statement.setUserId(sysUser.getUserId());

        List<Statement> list = statementService.selectStatementList(statement);
        ExcelUtil<Statement> util = new ExcelUtil<Statement>(Statement.class);
        util.exportExcel(response, list, "结算单数据");
    }

    /**
     * 获取结算单详细信息
     */
    @PreAuthorize("@ss.hasPermi('module:statement:id')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(statementService.selectStatementById(id));
    }

    /**
     * 新增结算单
     */
    @Log(title = "结算单", businessType = BusinessType.INSERT)
    @PreAuthorize("@ss.hasPermi('module:statement:add')")
    @PostMapping
    public AjaxResult add(@RequestBody Statement statement)
    {
        return toAjax(statementService.insertStatement(statement));
    }

    /**
     * 修改结算单
     */
    @Log(title = "结算单", businessType = BusinessType.UPDATE)
    @PreAuthorize("@ss.hasPermi('module:statement:edit')")
    @PutMapping
    public AjaxResult edit(@RequestBody Statement statement)
    {
        return toAjax(statementService.updateStatement(statement));
    }

    /**
     * 删除结算单
     */
    @Log(title = "结算单", businessType = BusinessType.DELETE)
    @PreAuthorize("@ss.hasPermi('module:statement:remove')")
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(statementService.deleteStatementByIds(ids));
    }
}
